<template>
  <div style="background: #ebeff4">
    <div class="app-container" style="background: #FFFFFF;" v-if="listshow">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

        <el-form-item label="客户编号" prop="customerId" v-if="false">
          <el-input v-model="queryParams.customerId" placeholder="请输入客户编号" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="订单编号" prop="orderId">
          <el-input style="width: 150px" v-model="queryParams.orderId" placeholder="请输入订单号" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="客户名称" prop="customer">
          <el-input style="width: 200px" v-model="queryParams.customer" placeholder="请输入客户名称" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="订单类型" prop="orderType">
          <el-select v-model="queryParams.orderType" placeholder="订单状态" clearable style="width: 150px">
            <el-option v-for="dict in dict.type.sys_order_type" :key="dict.value" :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="订单状态" clearable style="width: 150px">
            <el-option v-for="dict in dict.type.sys_order_state" :key="dict.value" :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单时间">

          <el-date-picker v-model="dateRange[0]" type="date" value-format="yyyy-MM-dd" placeholder="开始时间" style="width: 150px">
          </el-date-picker>

        </el-form-item>
        <el-form-item label="">
          <span>至</span>
        </el-form-item>
        <el-form-item label="">

          <el-date-picker v-model="dateRange[1]" type="date" value-format="yyyy-MM-dd" placeholder="结束时间" style="width: 150px">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="订单时间">
          <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
            start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        </el-form-item> -->
        <el-form-item>

          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="success" plain icon="el-icon-back" size="mini" @click="backqd"
            v-show="showback">返回渠道列表</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['CustomerorderMain:customerorder:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
            v-hasPermi="['CustomerorderMain:customerorder:edit']">修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
            v-hasPermi="['CustomerorderMain:customerorder:remove']">删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
            v-hasPermi="['CustomerorderMain:customerorder:export']">导出</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="info" plain icon="el-icon-download" size="mini" @click="adddd" v-if="false">订单选择弹窗</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="tborder"
            v-hasPermi="['CustomerorderMain:customerorder:tbdd']">同步订单数据</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="tborderywy"
            v-hasPermi="['CustomerorderMain:customerorder:tbddywy']">同步订单对应业务员</el-button>
        </el-col>
        <el-col :span="1.5" v-if="false">
          <el-button type="danger" plain icon="el-icon-download" size="mini" :disabled="multiple"
            @click="findkh">生成汇总合同</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="customerorderList" @selection-change="handleSelectionChange" border=""
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="订单号" align="center" prop="orderId" width="150" />
        <el-table-column label="客户帐号id" align="center" prop="customerId" v-if="false" />
        <el-table-column label="云服务类型编码" align="center" prop="serviceTypeCode" v-if="false" />
        <el-table-column label="产品类型" align="center" prop="serviceTypeName" width="140" />
        <el-table-column label="订单类型" align="center" prop="orderType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_order_type" :value="scope.row.orderType" />
          </template>
        </el-table-column>
        <el-table-column label="订单状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_order_state" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="客户名称/帐号" align="left" prop="userName" width="120">
          <template slot-scope="scope">
            <el-tooltip placement="top">
              <div slot="content">{{ scope.row.customer }}<br />{{ scope.row.accountName }}</div>
              <div>
                <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{ scope.row.customer }}
                </div>
                <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
                  {{ scope.row.accountName }}
                </div>
              </div>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column label="订单金额" align="right" prop="officialAmount">
          <template slot-scope="scope">
            {{ toFixed(scope.row.officialAmount) }}
          </template>
        </el-table-column>
        <el-table-column label="实付金额" align="right" prop="amountAfterDiscount">
          <template slot-scope="scope">
            {{ toFixed(scope.row.amountAfterDiscount) }}
          </template>
        </el-table-column>
        <!-- <el-table-column label="返点金额" align="right" prop="jeFdsj">
          <template slot-scope="scope">
            {{ toFixed(scope.row.jeFdsj) }}
          </template>
        </el-table-column> -->
        <el-table-column label="订单订单来源类型" align="center" prop="sourceType" v-if="false" />
        <el-table-column label="下单时间" align="center" prop="createTime1" v-if="false">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime1, '{y}-{m}-{d} {hh}:{mm}') }}</span>
            <!-- <span>{{ convertUTCTimeToLocalTime(scope.row.createTime1) }}</span> -->
          </template>
        </el-table-column>
        <el-table-column label="订单时间" align="center" prop="createTime1" width="90">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime1, '{y}-{m}-{d}') }}</span>
            <!-- <span>{{ convertUTCTimeToLocalTime(scope.row.paymentTime) }}</span> -->
          </template>
        </el-table-column>

        <el-table-column label="关联渠道" align="left" prop="deaname">
          <template slot-scope="scope">
            <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" :title="scope.row.deaname">
              {{ scope.row.deaname }}</div>
          </template>
        </el-table-column>

        <el-table-column label="实际渠道" align="left">
          <template slot-scope="scope">
            <div :title="scope.row.realDeaName" style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
              {{ scope.row.realDeaName }}</div>
          </template>
        </el-table-column>
        <el-table-column label="业务员" align="center">
          <template slot-scope="scope">
            <div :title="scope.row.realUName" style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"> {{
              scope.row.realUName }}</div>
          </template>
        </el-table-column>
        <el-table-column label="关联合同" align="center" prop="flag">

        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" v-if=xxtest width="140px"
          fixed="right">
          <template slot-scope="scope">
            <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['CustomerorderMain:customerorder:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['CustomerorderMain:customerorder:remove']"
          >删除</el-button> -->
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
              v-hasPermi="['CustomerorderMain:customerorder:edit']" v-if="false">修改</el-button>
         
            <el-button size="mini" type="text" icon="el-icon-connection" @click="xqtc(scope.row)">详情</el-button>
            <el-button size="mini" type="text" icon="el-icon-money" @click="editmoney(scope.row)"
              v-hasPermi="['CustomerorderMain:customerorder:sz']" v-if="false">设置</el-button>
            <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"
              v-hasPermi="['CustomerorderMain:customerorder:fp']">
              <el-button size="mini" type="text" icon="el-icon-d-arrow-right">分配</el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="handleResetPwd" icon="el-icon-key">分配业务员</el-dropdown-item>
                <el-dropdown-item command="handleAuthRole" icon="el-icon-circle-check">分配实际渠道</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />


      <!--详情弹窗-->
      <el-dialog title="订单详情" :visible.sync="openxq" width="85%" append-to-body :class="$style.ElDialog" v-if="true">
        <orderxx :key="deaval.orderId" :oid="deaval.orderId" :opid="deaval.indirectPartnerId"></orderxx>
      </el-dialog>

      <!-- 添加或修改订单列表对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="客户帐号id" prop="customerId">
            <el-input v-model="form.customerId" placeholder="请输入客户帐号id" />
          </el-form-item>
          <el-form-item label="云服务类型编码" prop="serviceTypeCode">
            <el-input v-model="form.serviceTypeCode" placeholder="请输入云服务类型编码" />
          </el-form-item>
          <el-form-item label="订单金额" prop="amountAfterDiscount">
            <el-input v-model="form.amountAfterDiscount" placeholder="请输入订单金额" />
          </el-form-item>
          <el-form-item label="订单优惠后金额" prop="officialAmount">
            <el-input v-model="form.officialAmount" placeholder="请输入订单优惠后金额" />
          </el-form-item>
          <el-form-item label="订单金额度量单位(1:元）" prop="measureId">
            <el-input v-model="form.measureId" placeholder="请输入订单金额度量单位(1:元）" />
          </el-form-item>
          <el-form-item label="支付时间" prop="paymentTime">
            <el-input v-model="form.paymentTime" placeholder="请输入支付时间" />
          </el-form-item>
          <el-form-item label="货币编码" prop="currency">
            <el-input v-model="form.currency" placeholder="请输入货币编码" />
          </el-form-item>
          <el-form-item label="合同id" prop="contractId">
            <el-input v-model="form.contractId" placeholder="请输入合同id" />
          </el-form-item>
          <el-form-item label="订单扣费详情" prop="amountInfo">
            <el-input v-model="form.amountInfo" placeholder="请输入订单扣费详情" />
          </el-form-item>
          <el-form-item label="订单详单" prop="orderInfo">
            <el-input v-model="form.orderInfo" placeholder="请输入订单详单" />
          </el-form-item>
          <el-form-item label="订单对应的订单项" prop="orderLineItems">
            <el-input v-model="form.orderLineItems" placeholder="请输入订单对应的订单项" />
          </el-form-item>
          <el-form-item label="订单创建者名称" prop="userName">
            <el-input v-model="form.userName" placeholder="请输入订单创建者名称" />
          </el-form-item>
          <el-form-item label="备用" prop="other1">
            <el-input v-model="form.other1" placeholder="请输入备用" />
          </el-form-item>
          <el-form-item label="备用" prop="other2">
            <el-input v-model="form.other2" placeholder="请输入备用" />
          </el-form-item>
          <el-form-item label="备用" prop="other3">
            <el-input v-model="form.other3" placeholder="请输入备用" />
          </el-form-item>
          <el-form-item label="备用" prop="other4">
            <el-input v-model="form.other4" placeholder="请输入备用" />
          </el-form-item>
          <el-form-item label="备用" prop="other5">
            <el-input v-model="form.other5" placeholder="请输入备用" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
      <!-- 设置价格弹窗 -->
      <el-dialog title="设置毛利参数" :visible.sync="open2" width="500px" append-to-body>
        <el-form ref="form2" :model="form2" :rules="rulesjs" label-width="80px">
          <el-form-item label="订单id" prop="deaId" v-if="false">
            <el-input v-model="form2.orderId" />
          </el-form-item>
          <el-row>
            <el-col :span="12">
              <el-form-item label="打款金额" prop="jeDk">
                <el-input v-model="form2.jeDk" placeholder="" @input.native="form2.jeDk =
                  form2.jeDk.replace
                    (form2.jeDk, RestrictedMoney
                      (form2.jeDk))" @change="materielExtraCostChange(form2.jeDk, 1)" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item>
                <span slot="label">
                  <span style="color:#898e99;">是否开票</span>
                </span>
                <el-checkbox></el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="拨款金额" prop="jeBk">
                <el-input v-model="form2.jeBk" placeholder="" @input.native="form2.jeBk =
                  form2.jeBk.replace
                    (form2.jeBk, RestrictedMoney
                      (form2.jeBk))" @change="materielExtraCostChange(form2.jeBk, 2)" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item> <span slot="label">
                  <span style="color:#898e99;">下单金额</span>
                </span>(<span style="color: red;">¥{{ toFixed(form2.sfje) }}</span>)</el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="返客金额" prop="jeFk">
                <el-input v-model="form2.jeFk" placeholder="" @input.native="form2.jeFk =
                  form2.jeFk.replace
                    (form2.jeFk, RestrictedMoney
                      (form2.jeFk))" @change="materielExtraCostChange(form2.jeFk, 3)" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item>
                <span slot="label">
                  <span style="color:#898e99;">是否前返</span>
                </span>
                <el-checkbox></el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="返渠金额" prop="jeFq">
                <el-input v-model="form2.jeFq" placeholder="" @input.native="form2.jeFq =
                  form2.jeFq.replace
                    (form2.jeFq, RestrictedMoney
                      (form2.jeFq))" @change="materielExtraCostChange(form2.jeFq, 4)" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item>
                <span slot="label">
                  <span style="color:#898e99;">是否前返</span>
                </span>
                <el-checkbox></el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="华为月返" prop="jeFdsj">
                <!-- <el-input v-model="form2.jeFd" oninput="value=value.replace(/[^0-9.]/g,'')"
          @blur="blur($event)" type="number"   /> -->

                <el-input v-model="form2.jeFdsj" placeholder="" @input.native="form2.jeFdsj =
                  form2.jeFdsj.replace
                    (form2.jeFdsj, RestrictedMoney
                      (form2.jeFdsj))" @change="materielExtraCostChange(form2.jeFdsj, 6)">

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="暂估月返" prop="jeFd">
                <el-input v-model="form2.jeFd" placeholder="" @input.native="form2.jeFd =
                  form2.jeFd.replace
                    (form2.jeFd, RestrictedMoney
                      (form2.jeFd))" @change="materielExtraCostChange(form2.jeFd, 5)">
                  <i slot="suffix" class="el-icon-camera" style="cursor:pointer ;" @click="copyfd"></i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="华为季返">
                <el-input v-model="form2.jejFdsj" placeholder="" @input.native="form2.jejFdsj =
                  form2.jejFdsj.replace
                    (form2.jejFdsj, RestrictedMoney
                      (form2.jejFdsj))" @change="materielExtraCostChange(form2.jejFdsj, 7)">

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="暂估季返">
                <el-input v-model="form2.jejFd" placeholder="" @input.native="form2.jejFd =
                  form2.jejFd.replace
                    (form2.jejFd, RestrictedMoney
                      (form2.jejFd))" @change="materielExtraCostChange(form2.jejFd, 8)">
                  <i slot="suffix" class="el-icon-camera" style="cursor:pointer ;" @click="copyjfd"></i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="实际毛利" prop="jeLrsj">
                <el-input v-model="form2.jeLrsj" type="number" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="暂估毛利" prop="jeLr">
                <el-input v-model="form2.jeLr" type="number" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" icon="el-icon-finished" @click="clickjs"></el-button>
          <el-button type="primary" @click="submitForm2">确 定</el-button>
          <el-button @click="cancel2">取 消</el-button>
        </div>
      </el-dialog>
      <!-- 订单选择弹窗测试 -->
      <el-dialog :title="title" :visible.sync="open1" width="900px" append-to-body>
        <el-form label-width="80px">
          <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="customerorderList1"
            @selection-change="handleSelectionChange1">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="订单id" align="center" prop="orderId" />
            <!-- <el-table-column label="客户帐号id" align="center" prop="customerId" /> -->
            <el-table-column label="云服务类型编码" align="center" prop="serviceTypeCode" />
            <el-table-column label="云服务类型名称" align="center" prop="serviceTypeName" />
            <el-table-column label="云服务类型编码" align="center" prop="serviceTypeCode" />
            <!-- <el-table-column label="客户订单订单来源类型" align="center" prop="sourceType" /> -->
            <el-table-column label="订单状态" align="center" prop="status" />
            <el-table-column label="订单类型" align="center" prop="orderType" />
            <el-table-column label="订单金额" align="center" prop="amountAfterDiscount" />
            <el-table-column label="订单优惠后金额" align="center" prop="officialAmount" />
            <!-- <el-table-column label="订单金额度量单位(1:元）" align="center" prop="measureId" /> -->
            <!-- <el-table-column label="支付时间" align="center" prop="paymentTime" />
      <el-table-column label="货币编码" align="center" prop="currency" />
      <el-table-column label="合同id" align="center" prop="contractId" />
      <el-table-column label="订单扣费详情" align="center" prop="amountInfo" />
      <el-table-column label="订单详单" align="center" prop="orderInfo" />
      <el-table-column label="订单对应的订单项" align="center" prop="orderLineItems" />
      <el-table-column label="订单创建者名称" align="center" prop="userName" /> -->
          </el-table>
          <pagination v-show="total1 > 0" :total="total1" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList1" />
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="ImportClick">导 入</el-button>
          <el-button @click="cancel1">取 消</el-button>
        </div>
      </el-dialog>
      <!-- 分配业务员弹窗测试 -->
      <el-dialog :title="title3" :visible.sync="open3" width="500px" append-to-body>
        <el-form :model="queryParamsUser" ref="queryFormUser" size="small" :inline="true" label-width="68px"
          @submit.native.prevent>
          <el-form-item label="姓名" prop="nickName">
            <el-input v-model="queryParamsUser.nickName" placeholder="请输入姓名" clearable
              @keyup.enter.native="handleUserQuery" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleUserQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQueryUser">重置</el-button>
          </el-form-item>
        </el-form>
        <el-form label-width="80px">
          <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="dealeruser"
            @selection-change="handleSelectionChangeUser">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="编号" align="center" prop="userId" />
            <el-table-column label="帐号" align="center" prop="userName" />
            <el-table-column label="姓名" align="center" prop="nickName" />
          </el-table>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="ywyClick">确 定</el-button>
          <el-button @click="cancel3">取 消</el-button>
        </div>
      </el-dialog>
      <!-- 分配渠道弹窗测试 -->
      <el-dialog :title="title4" :visible.sync="open4" width="1000px" append-to-body>
        <el-form :model="queryParamsQd" ref="queryFormQd" size="small" :inline="true" label-width="68px"
          @submit.native.prevent>
          <el-form-item label="渠道名称" prop="deaName">
            <el-input v-model="queryParamsQd.deaName" placeholder="请输入渠道名称" clearable
              @keyup.enter.native="handleQdQuery" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQdQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQueryQd">重置</el-button>
          </el-form-item>
        </el-form>
        <el-form label-width="80px">
          <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="dealerList"
            @selection-change="handleSelectionChangeQd">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="渠道编号" align="center" prop="deaId" />
            <el-table-column label="渠道名称" align="center" prop="deaName" />
            <el-table-column label="帐号" align="center" prop="deaUser" />
          </el-table>
          <pagination v-show="total4 > 0" :total="total4" :page.sync="queryParamsQd.pageNum"
            :limit.sync="queryParamsQd.pageSize" @pagination="getListDea" />
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="qdClick">确 定</el-button>
          <el-button @click="cancel4">取 消</el-button>
        </div>
      </el-dialog>
    </div>
 
  </div>
</template>

<script>
import { tblistCustomerorder, tbywy, listCustomerorder1, ImportCustomerorder, listCustomerorder, getCustomerorder, delCustomerorder, addCustomerorder, updateCustomerorder, insertxq, listCustomerorderItem, selectywy, updateqdc } from "@/api/CustomerorderMain/customerorder";
import {
  listDealerAll,
} from "@/api/DealerMain/dealer";
import { listuser } from "@/api/system/user";
import { GetMonA, GetMonB } from "@/api/public";
import orderxx from '@/views/Mycomponents/OrderMain/orderxx'
export default {
  dicts: ["sys_order_type", "sys_order_state"],
  name: "Customerorder",
  components: {
    orderxx
  },
  data() {
    return {
      showback: false,
      deaval: {
        //分配时，传值的parm
        orderId: null,
        indirectPartnerId: null,
      },
 
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中数组多先时
      ids1: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,

      total1: 0,
      dateRange: [],
      // 订单列表表格数据
      customerorderList: [],
 
      customerorderList1: [],
      xxtest: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,

      openxq: false,

      //分配业务员选中相关
      dealeruser: [],
      ywyval: {//分配时，传值的parm
        orderId: null,
        userId: null,

      },
      ywyid: [],//分配选中的业务员

      idsdeaid: '',
      open3: false,
      queryParamsUser: {
        nickName: null,
      },
      title3: "",
      //--------------------//

      //分配渠道相关
      open4: false,
      title4: "",
      dealerList: [],
      deid: [],//分配选中的渠道
      qdval: {//分配时，传值的parm
        realDea: null,
        orderId: null,
      },
      total4: 0,
      // 查询参数
      queryParamsQd: {
        pageNum: 1,
        pageSize: 10,
        Dtype: 2,
        deaName: null,
      },
      //--------------------//

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customer: null,
        customerId: null,
        serviceTypeCode: null,
        sourceType: null,
        status: null,
        orderType: null,
        amountAfterDiscount: null,
        officialAmount: null,
        measureId: null,
        paymentTime: null,
        currency: null,
        contractId: null,
        amountInfo: null,
        orderInfo: null,
        orderLineItems: null,
        userName: null,
        other1: null,
        other2: null,
        other3: null,
        other4: null,
        other5: null
      },
      // 表单参数
      form: {},
      form2: {

      },
      // 表单校验
      rules: {
      },
      //金额弹窗校验
      rulesjs: {
        // jeDk: [
        // { required: true, message: "打款金额不能为空", trigger: "blur" },
        // ],
        // jeFd: [
        // { required: true, message: "返点金额不能为空", trigger: "blur" },
        // ],
        // jeFdsj: [
        // { required: true, message: "实际返点不能为空", trigger: "blur" },
        // ],
        // jeFk: [
        // { required: true, message: "返客金额不能为空", trigger: "blur" },
        // ],
        // jeFq: [
        // { required: true, message: "返渠金额不能为空", trigger: "blur" },
        // ],
      },
      listshow: true,
   
    };
  },
  created() {
    this.dateRange[0] = GetMonA(3);
    this.dateRange[1] = GetMonB();
    this.queryParams.customer = this.$route.query.did;
    if (this.queryParams.customer != undefined) {
      this.handleQuery();
      this.showback = true;
    }
    else
      //执行查询搜索事件
      this.getList();

  },
  methods: {
    //返回渠道列表
    backqd: function () {

      this.$router.push(
        {
          path: '/client/customerinfo',
          methods: 'post',
          query: {

          }
        })
    },
    //跳转到合同页面
    findkh: function (row) {
      this.$router.push(
        {
          path: '/htxg/agreementht',
          methods: 'post',
          query: {
            did: this.ids,
          }
        })
    },
    //https://blog.csdn.net/return_js/article/details/102840141  //输入正负，带2位小数
    plusOrMinus(values) {
      let newValue;
      if (!(/[^0-9.-]/g.test(values))) {
        newValue = values.replace(/[^\-\d.]/g, '').replace(/\-{2,}/g, '-').replace(/\-{2,}/g, '-').replace(/^\./g, '')
          .replace(/\.{2,}/g, '.')
          .replace('.', '$#$')
          .replace(/\./g, '')
          .replace('$#$', '.');
        if (newValue.toString().indexOf('.') > 0 && Number(newValue.toString().split('.')[1].length) > 2) {
          newValue = parseInt(parseFloat(newValue) * 100) / 100;
        }
        if ((newValue.toString().split('-').length - 1) > 1) {
          newValue = parseFloat(newValue) || '';
        }
        if ((newValue.toString().split('-').length) > 1 && newValue.toString().split('-')[0].length > 0) {
          newValue = parseFloat(newValue) || '';
        }
        if (newValue.toString().length > 1 && (newValue.toString().charAt(0) === '0' || (newValue.toString().length > 2 && newValue.toString().charAt(0) === '-' && newValue.toString().charAt(1) === '0' && newValue.toString().charAt(2) !== '.')) && newValue.toString().indexOf('.') < 1) {
          newValue = parseFloat(newValue) || '';
        }
        // 判断整数位最多为9位
        if (newValue.toString().indexOf('.') > 0 && Number(newValue.toString().split('.')[0].length) > 9) {
          newValue = `${newValue.toString().substring(0, 9)}.${newValue.toString().split('.')[1]}`;
        } else if (newValue.toString().indexOf('.') < 0 && Number(newValue.toString().split('.')[0].length) > 9) {
          newValue = newValue.toString().substring(0, 9);
        }
      } else {
        newValue = values.replace(/[^0-9.-]/g, '');
      }
      return newValue;
    },

    // 额外费用校验输入正负数， 保留2位小数 调用公共方法
    RestrictedMoney(values) {
      return this.plusOrMinus(values.toString());
    },
    // 结合change事件对失去焦点进行判断，防止输入一些无效值
    materielExtraCostChange(item, type) {
      // 防止删除为空
      if (!item) {
        item = '0.00';
      }
      // 一些错误金额输入的判断
      if (item.toString().indexOf('.') > 0 && Number(item.toString().split('.')[1].length) < 1) {
        item = item.toString().split('.')[0];
      }
      // 一些错误金额输入的判断
      if (!item || item === '-' || item === '-0') {
        item = '0.00';
        return;
      }
      item = parseFloat(item).toFixed(2);
      if (type == 1)
        this.form2.jeDk = item;
      if (type == 2)
        this.form2.jeBk = item;
      if (type == 3)
        this.form2.jeFk = item;
      if (type == 4)
        this.form2.jeFq = item;
      if (type == 5)
        this.form2.jeFd = item;
      if (type == 6)
        this.form2.jeFdsj = item;
      if (type == 7)
        this.form2.jejFdsj = item;
      if (type == 8)
        this.form2.jejFd = item;

    },

    blur(e) {

      if (e.target.value.indexOf(".") != -1) {
        let str = e.target.value.split(".");
        if (str[0].length > 0) {
          let arr = str[0].split("");
          let res = arr.every((item, index) => {
            return item == 0 || item == "0";
          });
          if (res) {
            if (str[1]) {
              e.target.value = "0." + str[1].match(/^\d*(\.?\d{0,2})/g)[0] || ""; //match只保留后两位
            } else {
              e.target.value = "0.00";
            }
          } else {
            if (str[1]) {
              e.target.value = (str[0].replace(/\b(0+)/g, "") + "." + str[1]).match(/^\d*(\.?\d{0,2})/g)[0] || ""; //只保留后两位
            } else {
              e.target.value = str[0].replace(/\b(0+)/g, "") + ".00";
            }
          }
        }
        if (str[1].length == 1) {
          e.target.value = e.target.value + "0";
        }
      } else {
        let arr = e.target.value.split("");
        let res = arr.every((item, index) => {
          return item == 0 || item == "0";
        });
        if (res) {
          e.target.value = "0.00";
        } else {
          e.target.value = e.target.value.replace(/\b(0+)/g, "") + ".00";
        }
      }
    },
    //保留两位，不足补位
    toFixed(num) {
      return (Math.round(num * 100) / 100).toFixed(2);
    },
    //复制返点金额
    copyfd() {
      this.form2.jeFd = this.form2.jeFdsj;
    },
    //复制季返点金额
    copyjfd() {
      this.form2.jejFd = this.form2.jejFdsj;
    },
    //计算利润
    clickjs() {
      //必须转成int 才行，否则会计算不正确
      this.$refs["form2"].validate(valid => {
        if (valid) {

          //为空时赋值0
          if (this.form2.jeDk == null)
            this.form2.jeDk = "0.00";
          if (this.form2.jeBk == null)
            this.form2.jeBk = "0.00";
          if (this.form2.jeFd == null)
            this.form2.jeFd = "0.00";
          if (this.form2.jeFdsj == null)
            this.form2.jeFdsj = "0.00";
          if (this.form2.jeFk == null)
            this.form2.jeFk = "0.00";
          if (this.form2.jeFq == null)
            this.form2.jeFq = "0.00";
          if (this.form2.jejFdsj == null)
            this.form2.jejFdsj = "0.00";
          if (this.form2.jejFd == null)
            this.form2.jejFd = "0.00";

          const a = this.toFixed(parseInt(this.form2.jeDk) - parseInt(this.form2.jeBk));
          const b = this.toFixed(parseInt(a) + parseInt(this.form2.jeFdsj));

          const c = this.toFixed(parseInt(b) - parseInt(this.form2.jeFk));
          const d = this.toFixed(parseInt(c) - parseInt(this.form2.jeFq));
          const e = this.toFixed(parseInt(d) + parseInt(this.form2.jejFdsj));

          const b1 = this.toFixed(parseInt(a) + parseInt(this.form2.jeFd));
          const c1 = this.toFixed(parseInt(b1) - parseInt(this.form2.jeFk));
          const d1 = this.toFixed(parseInt(c1) - parseInt(this.form2.jeFq));
          const e1 = this.toFixed(parseInt(d1) + parseInt(this.form2.jejFd));
          console.log(e);
          console.log(d1);
          this.form2.jeLrsj = e;
          this.form2.jeLr = e1;
          //this.form2 = Object.assign({},this.form2);
        }
      });

    },
    numFilter(value) {
      let realVal = parseFloat(value).toFixed(2);
      return realVal;
    },
    /** 查询订单列表列表 */
    getList() {
      //判断表格列是否显示。测试管用
      if (['CustomerorderMain:customerorder:edit'].length > 0)
        this.xxtest = true;
      this.loading = true;
      listCustomerorder(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        // listCustomerorder(this.queryParams).then(response => {
        this.customerorderList = response.rows;
        this.total = response.total;
        this.loading = false;
        console.log(response.rows);
      });

    },

    /** 查询订单列表列表 */
    getList1() {

      this.loading = true;
      listCustomerorder1(this.queryParams).then(response => {
        this.customerorderList1 = response.rows;
        this.total1 = response.total1;
        this.loading = false;
      });
    },
 
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel1() {
      this.open1 = false;
      this.reset();
    },
    cancel2() {
      this.open2 = false;
      this.reset();
    },
    cancel3() {
      this.open3 = false;
      this.reset();
    },
    cancel4() {
      this.open4 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,
        customerId: null,
        customer: null,
        serviceTypeCode: null,
        sourceType: null,
        status: null,
        orderType: null,
        amountAfterDiscount: null,
        officialAmount: null,
        measureId: null,
        createTime1: null,
        paymentTime: null,
        currency: null,
        contractId: null,
        amountInfo: null,
        orderInfo: null,
        orderLineItems: null,
        userName: null,
        other1: null,
        other2: null,
        other3: null,
        other4: null,
        other5: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /**分配业务员窗口重置 */
    resetQueryUser() {
      this.resetForm("queryFormUser");
      this.handleUserQuery();
    },
    /**分配渠道窗口重置 */
    resetQueryQd() {
      this.resetForm("queryFormQd");
      this.handleQdQuery();
    },
    /** 搜索按钮操作 */
    handleUserQuery() {
      this.getListuser();
    },
    /** 搜索按钮操作 */
    handleQdQuery() {
      this.getListDea();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 弹窗多选框选中数据1
    handleSelectionChange1(selection) {
      this.ids1 = selection.map(item => item.orderId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单列表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderId = row.orderId || this.ids
      getCustomerorder(orderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单列表";
      });
    }, 
    /** 查看订单情况 */
    xqtc(row) {
      this.openxq = true;
      this.deaval.orderId = row.orderId;
      this.deaval.indirectPartnerId = row.indirectPartnerId;
      console.log(this.deaval.orderId);
    },
    /** 查看价格设置*/
    editmoney(row) {
      this.resetForm("form2");
      getCustomerorder(row.orderId).then(response => {
        this.form2 = response.data;
        this.form2.sfje = response.data.amountAfterDiscount;
        this.open2 = true;
      });
    },
 
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderId != null) {
            updateCustomerorder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCustomerorder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 设置价格提交按钮 */
    submitForm2() {
      this.clickjs();
      this.$refs["form2"].validate(valid => {
        if (valid) {
          updateCustomerorder(this.form2).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open2 = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$modal.confirm('是否确认删除订单列表编号为"' + orderIds + '"的数据项？').then(function () {
        return delCustomerorder(orderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('CustomerorderMain/customerorder/export', {
        ...this.queryParams
      }, `customerorder_${new Date().getTime()}.xlsx`)
    },
    /** 新增按钮操作 */
    adddd() {
      this.open1 = true;
      this.title = "订单选择弹窗";
      this.getList1();
    },
    /** 导入订单搞操作 */
    ImportClick(row) {
      const orderIds = row.orderId || this.ids1;
      this.$modal.confirm('是否导入"' + orderIds + '"的数据项？').then(function () {
        return ImportCustomerorder(orderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("导入成功");
      }).catch(() => { });
    },
    /** 同步订单 */
    tborder() {

      this.queryParams.other1 = this.dateRange[0];
      this.queryParams.other2 = this.dateRange[1];
      tblistCustomerorder(this.queryParams);
      this.$modal.msgSuccess("同步任务已下发");
      this.queryParams.other1 = null;
      this.queryParams.other2 = null;
    },
    /** 同步订单对应业务员 */
    tborderywy() {
      this.loading = true;
      tbywy(this.queryParams).then(response => {
        this.getList();
        this.loading = false;
      });
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleResetPwd":
          this.handleResetPwd(row);
          break;
        case "handleAuthRole":
          this.handleAuthRole(row);
          break;
        default:
          break;
      }
    },
    handleResetPwd(row) {
      this.idsdeaid = row.orderId;
      this.open3 = true;
      this.title3 = "分配业务员";
      this.getListuser();
    },
    handleAuthRole(row) {
      this.idsdeaid = row.orderId;
      this.open4 = true;
      this.title4 = "分配渠道";
      this.getListDea();
    },
    /** 查询分配列表 */
    getListuser() {
      this.loading = true;
      listuser(this.queryParamsUser).then(response => {
        this.dealeruser = response.rows;
        this.loading = false;
      });
    },
    /** 查询分配渠道列表 */
    getListDea() {

      this.loading = true;
      listDealerAll(this.queryParamsQd).then((response) => {
        this.dealerList = response.rows;
        this.total4 = response.total;
        this.loading = false;

      });
    },
    /** 分配业务员搞操作 */
    ywyClick() {

      const orderIds = this.ywyid; //选中的用户
      if (orderIds.length > 1) {
        alert("只能选择一个业务员");
        return;
      }
      this.ywyval.orderId = this.idsdeaid;
      this.ywyval.userId = this.ywyid[0];

      console.log(this.ywyval.orderId);
      console.log(this.ywyval.userId);

      selectywy(this.ywyval).then(response => {
        this.open3 = false;
        this.$modal.msgSuccess("分配成功");
        this.getList();
      });
    },
    /** 分配渠道搞操作 */
    qdClick() {
      console.log(this.deid);
      if (this.deid.length > 1) {
        alert("只能选择一个渠道");
        return;
      }
   
      this.qdval.realDea = this.deid[0];
      this.qdval.orderId = this.idsdeaid;

      updateqdc(this.qdval).then(response => {
        this.open4 = false;
        this.$modal.msgSuccess("修改成功");
        this.getList();
      });

    },
    // 分配弹窗多选框选中数据1
    handleSelectionChangeUser(selection) {
      this.ywyid = selection.map(item => item.userId)
      this.ywyname = selection.map(item => item.nickName)
      this.ywycode = selection.map(item => item.userName)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 分配弹窗多选框选中数据1 渠道
    handleSelectionChangeQd(selection) {
      this.deid = selection.map(item => item.deaId)

      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  }

};
</script>
<style>
.el-table th.gutter {
  display: table-cell !important;
  /* 解决表头线未对齐 */
}
</style>
<style lang="scss" module>
  .ElDialog {
    :global .el-dialog__body {
      padding: 1px !important;
    }
  }
</style>